<?php

class LeaveManage extends MySQLCN {

    function Add() {
        $qry = "INSERT INTO `leaves_details` 
            ( `emp_id`, `reporting_mgr`, `from_date`, 
              `to_date`, `leave_priority`, `leave_type`, `leave_subject`, `leave_msg`) VALUES 
            ( '{$_POST['uid']}', '{$_POST['rptid']}', '{$_POST['from']}','{$_POST['to']}', '{$_POST['leavepriority']}', '{$_POST['leavetype']}', '{$_POST['leavesub']}', '{$_POST['message']}')";
        return $this->insert($qry);
    }

    function Update($EmpID) {
        $check = $this->get($EmpID);
        if ($check == NULL) {
            return false;
        }
        $qry = "UPDATE `leaves_details` SET
              `reporting_mgr` = '{$_POST['rptid']}', 
              `from_date` = '{$_POST['form']}', 
              `to_date` = '{$_POST['to']}',
              `leave_priority` = '{$_POST['leavepriority']}', 
              `leave_type` = '{$_POST['leavetype']}', 
              `leave_subject` = '{$_POST['leavesub']}', 
              `leave_msg` = '{$_POST['message']}'
			   WHERE leaveid = '{$EmpID}'";
        return $this->insert($qry);
    }

    function Delete($EmpID) {
        $qry = "DELETE FROM `leaves_details` WHERE leaveid = '{$EmpID}'";
        return $this->insert($qry);
    }

    function get($EmpID) {
        $qry = "SELECT * 
                FROM `leaves_details` WHERE  leaveid= '{$EmpID}'";
        return $this->select($qry);
    }

	function AllList() {
    $qry = "SELECT lev.*,emp.*,dept.* 
     FROM leaves_details as lev INNER JOIN users as emp ON lev.emp_id=emp.id
     INNER JOIN dept_master as dept ON emp.department=dept.dept_id";
	 
	$conditions2 = array();
	$conditions2[] = 'Leave_status = 0';
		if(count($conditions2)) {
			$qry.= ' WHERE '.implode(' AND ', $conditions2);
		} 
	 
        return $this->select($qry);
		
		
		
    }
	function AllList1() {
	
    $qry = "SELECT lev.*,emp.*,dept.* 
     FROM leaves_details as lev INNER JOIN users as emp ON lev.emp_id=emp.id
     INNER JOIN dept_master as dept ON emp.department=dept.dept_id";
	 
	$conditions2 = array();
	$conditions2[] = 'Leave_status = 1';
		if(count($conditions2)) {
			$qry.= ' WHERE '.implode(' AND ', $conditions2);
		} 
	 
        return $this->select($qry);
		
		
		
    }
    function getReportMgr($EmpID) {
        $qry = "SELECT Name 
                FROM `users` WHERE id = '{$EmpID}'";
        return $this->select($qry);
    }
	function udateleavestatus($lv_id) 
	{
        $check = $this->get($lv_id);
        if ($check == NULL) {
            return false;
        }
        $qry = "UPDATE `leaves_details` SET
              `Leave_status` = '1'
			   WHERE leaveid = '{$lv_id}'";
        return $this->insert($qry);
	
}
}
?>